import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 通过 defineStore 定义数据仓库，返回获取仓库的函数，命名一般是 useXxxStore
export const useCounterStore = defineStore("counter", () => {
  // states 数据
  const totalCount = ref(0);

  // 修改数据
  const addTotalCount = (num: number) => {
    totalCount.value += num;
  };
  // getters 计算属性
  const doubleTotalCount = computed(() => {
    return totalCount.value * 2;
  });

  // 必须返回全局数据
  return { totalCount, addTotalCount, doubleTotalCount };
},
  { persist: true }
  );
